// components/order-cancel/index.js
import __config from "../../config/env";
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    orderId: {
      type: String,
      value: null
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    loading: false,
    reasonList: ['不具备维修条件', '联系不上客户'],
    // 取消原因
    cancelReason: null,
    // 取消简要描述
    cancelDesc: null,
  },
  /**
   * 组件的方法列表
   */
  methods: {
    RadioChange(e) {
      this.setData({
        cancelReason: e.detail.value
      })
    },
    // 取消简要描述
    textareaInput(e) {
      this.setData({
        cancelDesc: e.detail.value
      })
    },
    // 提交
    orderSub() {
      const that = this
      let id = this.data.orderId
      let cancelReason = this.data.cancelReason
      let cancelDesc = this.data.cancelDesc
      let error = ''
      if (!cancelReason) {
        error = '请选择取消订单的原因'
      } else if (!cancelDesc) {
        error = '请输入简要描述'
      }
      if (error) {
        wx.showToast({
          title: error,
          icon: "none",
          duration: 2000
        });
        return
      }
      that.setData({
        loading: true
      })
      app.api.providerOrderCancel({
        orderId: id,
        cancelReason: cancelReason,
        cancelDesc: cancelDesc
      }).then(res => {
        that.setData({
          loading: false,
          orderId: null,
          cancelReason: null,
          cancelDesc: null
        })
        that.triggerEvent('cancelOrderEvent')
      }).catch(() => {
        this.setData({
          loading: false
        })
      })
    }
  }
})